package com.xqgl.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.xqgl.bean.Equip;
import com.xqgl.service.EquipDaoImp;

/**
 * Servlet implementation class addEquipServlet
 */
@WebServlet("/addEquipServlet")
public class addEquipServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public addEquipServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;Charset=utf-8");
		String villagename = request.getParameter("villagename");
		String equipnum = request.getParameter("equipnum");
		String equipname = request.getParameter("equipname");
		String brand = request.getParameter("brand");
		Double unitprice = Double.parseDouble(request.getParameter("unitprice"));
		int purchasenum = Integer.parseInt(request.getParameter("purchasenum"));
		String purchasedate = request.getParameter("purchasedate");
		String servicelife = request.getParameter("servicelife");
		String equipctime = request.getParameter("equipctime");
		
		Equip equip = new Equip();
		equip.setVillagename(villagename);
		equip.setEquipnum(equipnum);
		equip.setEquipname(equipname);
		equip.setBrand(brand);
		equip.setUnitprice(unitprice);
		equip.setPurchasenum(purchasenum);
		equip.setPurchasedate(purchasedate);
		equip.setServicelife(servicelife);
		equip.setEquipctime(equipctime);
		
		EquipDaoImp imp = new EquipDaoImp();
		try {
			imp.add(equip);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		response.sendRedirect("equiplist.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
